package com.luis.toolbox.common;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.stereotype.Service;

import com.luis.toolbox.intf.MyTransformer;
import com.luis.toolbox.intf.PrepareHandler;

@Service
public class CommonHandler {

	/**Handler的入口，通过调用方法sendToHandler将消息发送到handlerInboundChannel*/
	@MessagingGateway(name="defaultGateway", defaultRequestChannel = "handlerInboundChannel")
	public interface DefaultGateway {
		void sendToHandler(String data);
	}

	/*设置默认的 handler 和 transformer，实现消息透传*/
	@Bean
	@ConditionalOnMissingBean(PrepareHandler.class)
	public PrepareHandler handler() {
		return (payload,header) -> payload;
	}
	
	@Bean
	@ConditionalOnMissingBean(MyTransformer.class)
	public MyTransformer transformer() {
		return payload -> payload;
	}


}
